package com.atguigu.common.validator.customValidAnnotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class SortValidator implements ConstraintValidator<ValidValue,Integer> {
    Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(ValidValue constraintAnnotation) {
        int[] value = constraintAnnotation.value();
        for (int i = 0; i < value.length; i++) {
            set.add(value[i]);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
